/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.webserver.handler;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mb.mbmiddle.MbPartMiddle;

/**
 *
 * @author thanh.nguyenchi
 */
public class BaseServlet extends HttpServlet{   
    public String newLine = System.getProperty("line.separator");
            
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        
    }
    
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        
    }
    
    public void log(String sMsg){
        MbPartMiddle.objWebLog.log(sMsg);
    }
    
    public String fetch( String target ) { 
	StringBuffer buf = new StringBuffer();
	try {                               
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(target)                        
                )
            );
            if ( reader != null ) {  
                try {  
                    String line;
                    while ((line = reader.readLine()) != null) {
                        buf.append(line).append("\r\n");  
                    }
                } catch ( Exception x ) { }
                finally {
                    reader.close();  
                }
            }	
	} 
	catch ( Exception ex ) {
            ex.printStackTrace();
            buf.append("");
	}
	return buf.toString();           
    } 
}
